1,19 → 1,19 |
/*------------------------------------------------------------------------------------------*\ |
This file contains material supporting chapter 9 of the cookbook: |
Computer Vision Programming using the OpenCV Library. |
by Robert Laganiere, Packt Publishing, 2011. |
Computer Vision Programming using the OpenCV Library. |
by Robert Laganiere, Packt Publishing, 2011. |
|
This program is free software; permission is hereby granted to use, copy, modify, |
and distribute this source code, or portions thereof, for any purpose, without fee, |
subject to the restriction that the copyright notice may not be removed |
or altered from any source or altered source distribution. |
The software is released on an as-is basis and without any warranties of any kind. |
In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
The author disclaims all warranties with regard to this software, any use, |
and any consequent failure, is purely the responsibility of the user. |
This program is free software; permission is hereby granted to use, copy, modify, |
and distribute this source code, or portions thereof, for any purpose, without fee, |
subject to the restriction that the copyright notice may not be removed |
or altered from any source or altered source distribution. |
The software is released on an as-is basis and without any warranties of any kind. |
In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
The author disclaims all warranties with regard to this software, any use, |
and any consequent failure, is purely the responsibility of the user. |
|
Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
\*------------------------------------------------------------------------------------------*/ |
Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
\*------------------------------------------------------------------------------------------*/ |
|
#ifndef CAMERACALIBRATOR_H |
#define CAMERACALIBRATOR_H |
26,37 → 26,58 |
#include "opencv2/calib3d/calib3d.hpp" |
#include <opencv2/highgui/highgui.hpp> |
|
class CameraCalibrator { |
class CameraCalibrator |
{ |
|
// input points |
std::vector<std::vector<cv::Point3f>> objectPoints; |
std::vector<std::vector<cv::Point2f>> imagePoints; |
// output Matrices |
cv::Mat cameraMatrix; |
cv::Mat distCoeffs; |
// flag to specify how calibration is done |
int flag; |
// used in image undistortion |
cv::Mat map1,map2; |
bool mustInitUndistort; |
// input points |
std::vector<std::vector<cv::Point3f> > objectPoints; |
std::vector<std::vector<cv::Point2f> > imagePoints; |
// output Matrices |
cv::Mat cameraMatrix; |
cv::Mat distCoeffs; |
// flag to specify how calibration is done |
int flag; |
// used in image undistortion |
cv::Mat map1, map2; |
bool mustInitUndistort; |
|
public: |
CameraCalibrator() : flag(0), mustInitUndistort(true) {}; |
public: |
CameraCalibrator() : |
flag(0), mustInitUndistort(true) |
{ |
} |
; |
|
// Open the chessboard images and extract corner points |
int addChessboardPoints(const std::vector<std::string>& filelist, cv::Size & boardSize); |
// Add scene points and corresponding image points |
void addPoints(const std::vector<cv::Point2f>& imageCorners, const std::vector<cv::Point3f>& objectCorners); |
// Calibrate the camera |
double calibrate(cv::Size &imageSize); |
// Set the calibration flag |
void setCalibrationFlag(bool radial8CoeffEnabled=false, bool tangentialParamEnabled=false); |
// Remove distortion in an image (after calibration) |
cv::Mat CameraCalibrator::remap(const cv::Mat &image); |
// Open the chessboard images and extract corner points |
int |
addChessboardPoints(const std::vector<std::string>& filelist, |
cv::Size & boardSize); |
// Add scene points and corresponding image points |
void |
addPoints(const std::vector<cv::Point2f>& imageCorners, |
const std::vector<cv::Point3f>& objectCorners); |
// Calibrate the camera |
double |
calibrate(cv::Size imageSize); |
// Set the calibration flag |
void |
setCalibrationFlag(bool radial8CoeffEnabled = false, |
bool tangentialParamEnabled = false); |
// Remove distortion in an image (after calibration) |
cv::Mat |
remap(const cv::Mat &image); |
|
// Getters |
cv::Mat getCameraMatrix() { return cameraMatrix; } |
cv::Mat getDistCoeffs() { return distCoeffs; } |
// Getters |
cv::Mat |
getCameraMatrix() |
{ |
return cameraMatrix; |
} |
cv::Mat |
getDistCoeffs() |
{ |
return distCoeffs; |
} |
}; |
|
#endif // CAMERACALIBRATOR_H |